using ConfClient;
using SvCore.Tcp;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zpb;
using static ConfClient.Conf;
using static UnityEditor.Progress;

public class MudPerforms : MonoBehaviour
{
    public ModButton ModButton;

    public Component PerformsContent;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void UpdatePerforms()
    {
        PerformsContent.transform.DestroyChildren();

        foreach (var item in GameData.PlayerInfoPerform.Performs) { NewButton(item); }
    }
    public void NewButton(string perform)
    {
        if (!ConfPerform.TryGetValue(perform, out var conf))
        {
            return;
        }
        var btn = PerformsContent.InstAdd(ModButton);
        btn.Text = conf.Name;
        btn.SetButtonColor(Zsc.Color(128, 128, 0));
        btn.FontSize = 30;
        btn.SetTags(perform);
        btn.SetOnClick(OnClickBtn);
    }
    public void G2CNtfPerforms(MyPackage pack)
    {
        pack.GetMsg(out G2CNtfPerforms rsp);

        GameData.PlayerInfoPerform = rsp.InfoPerform;

        UpdatePerforms();
    }
    public void G2CPerformAct(MyPackage pack)
    {
    }
    public void OnClickBtn(ModButton btn)
    {
        var perform = (string)btn.ModTags[0];
        MySocket.Send(new C2GPerformAct() { Perform = perform });
    }
}
